package test;

import jm.JMC;
import jm.music.data.CPhrase;
import jm.music.data.Part;
import jm.music.data.Score;
import jm.util.Play;
import jm.util.View;

public class MyChordTest1 implements JMC{

	public static void main(String[] args) {
		Score score = new Score("和弦测试");
		Part part = new Part("Piano", PIANO, 0);
//		int[] pitches = {C4,D4,E4,F4,G4, A4,B4,C5};
		//音高
		int[] pitches = {A4,G4,E4,D4,C4,  
				         E4,D4,C4,A3,G3,  
				         G3,A3,G3,A3,
				         C4,D4,E4,G4,
				         A4,G4,E4,D4,C4,D4};
		//节奏
		double[] rhythms ={0.75, 0.25, 0.5, 0.5,    2,  
				           0.75, 0.25, 0.5, 0.5,    2, 
				           0.75, 0.25, 0.75, 0.25, 
				           0.75, 0.25, 0.5, 0.5, 
				           0.75, 0.25, 0.25,0.25,0.5,2};
		
		for(int i=0; i<pitches.length; i++) {
			part.addCPhrase(rootPosition(pitches[i],rhythms[i]));
		}
		part.setTempo(FFF);
		score.add(part);
		
		View.show(score);
		Play.midi(score);

	}
	
	private static CPhrase rootPosition(int rootPitch, double rhythmValue) {
		// build the chord from the rootPitch 
	 	int[] pitchArray = new int[4];
	 	pitchArray[0] = rootPitch;
	 	pitchArray[1] = rootPitch + 4;
	 	pitchArray[2] = rootPitch + 7;
	 	pitchArray[3] = rootPitch + 10;
	 	//add chord to the part
		CPhrase chord = new CPhrase();
		chord.addChord(pitchArray, rhythmValue);
		return chord;
	}

}
